templates to replace variables in template files and implement some simple logic files5 handlers and notity are used in conjunction, the action triggered by a specific condition, satisfies the condition to execute, otherwise does not execute6 tags tag specifies a task execution that selects some code in the run playbook. The ansible is idempotent, so it will aut
Ansible is a lightweight batch configuration management tool for agentless, because of the relatively late (13) development based on ansible less relevant documents, so here are some small experiments, combined with the existing data and source code, explore the Ansible two times development.The contents of the essay are divided into three parts.
Preface
Two previous articles talk about ansible deployment and use of ansible modules respectively. They have an initial understanding of ansible. This article focuses on introducing playbook.For details about ansible deployment, click ansible first: DeploymentAnsible modul
execute, and handlers defines which calls
Processor
Is a simple example:
How can I run my defined scripts? Use the ansible-playbook command, for example, ansible-playbook/root/first. yml.
Variable:
Variable name: it may consist of letters, numbers, and underscores. It can
information for vars_prompt in playbook, you can implement the value of the passed-in variable by interacting when you run playbook.
Cat Prompt.yml
---
-hosts:test
remote_user:root
vars_prompt:
-Name: "Var1"
prompt: "input Value for var1 "
private:no
-Name:" Var2 "
prompt:" Input value for var2 "
private:yes
Playbook is a list of one or more "play"The main function of play is to dress up a pre-set host as a role defined in advance through the task in ansible. Fundamentally, the so-called task is nothing more than a call to Ansible's module. By organizing multiple play in one playbook, you can connect them to run in a pre-p
/etc/ntp/rypto/pwkeys/etc/ Ntp/keysvars/main.yml #变量配置文件---#Variable listedhere is applicable to all host groups ntpserver:210.72.145.44"Roles/web"handlers/main.yml #处理程序文件---- name:restart nginx service:name=nginx state=restarted tasks/main.yml #任务列表文件 ----name:ensure nginx is at the latest version # yum:pkg=nginx state=latest # yum Install the latest version of Nginx - Name:write the Nginx Config file template:src =/home/test/ansible
Perform a playbookThe above sections already have a preliminary understanding of Playbook's syntax, so how do you run a playbook?This is very simple, here's an example of running playbook in parallel, the level of parallelism is 10Ansible-playbook Playbook.yml-f 10Ansible-pull (pull configuration rather than push confi
execution. * Vim/opt/ABC. yml-hosts: webserver # specifies the Host group, which can be one or more. Remote_user: Root # specify the user name for remote host execution * Remote_user can also define the user to run commands on the managed host through sudo, or even specify the user to switch to when sudo is used by sudo_user. * Vim/opt/sudo. yml-hosts: webserver remote_user: Root become: yes # parameters later than version 2.6, which was previously
The previous article introduced the installation configuration and example of Ansible: http://msiyuetian.blog.51cto.com/8637744/1748143The following article mainly introduces Ansible's playbook, playbook is equivalent to the module or function written into the configuration file, and then we execute the configuration file to achieve the purpose of remote operatio
I. Description of the EnvironmentServer with Ansible installed: 192.168.13.45Test environment server: 192.168.13.49/home/app/api-tomcat/webapps/api.war a new version of the war package location for the test environmentProduction Environment server: 192.168.13.51/home/app/api-tomcat/webapps/api.war for production Environment War package location/HOME/APP/API-TOMCAT/WEBAPPS/API for production environment Project location/home/app/tomcat.bak/ api/webapps
need to send the key to the production environment host2. Upgrade and RollbackUpgradeAnsible-playbook/home/app/api.yml-vRolling backAnsible-playbook/home/app/api-rollback.yml-vAnsible-playbook followed by the Yml file path written earlier,-V is to display detailed execution information3. AttentionIf you perform an upgrade and rollback of the yml file in Jenkins,
Ansible's script is written in the Yaml language, with the following basic syntax:
Basic syntax:1. Case2, the same level to be aligned, indentation representation level3, indentation is not allowed to use the TAB key4, the indentation of the number of spaces does not stipulate that the same element can be distinguished
Supported Data Structures:1. Object: A set of key-value pairs, also known as a map/hash/dictionaryExample: Name:example key: Value2, array: A set of
Meet a demand today when using Ansible-playbook after executing a script, according to the content returned by the script to determine whether to continue execution or break execution, query official website found using Register Register can be used to achieve the recording script output, using when+ Fail module to determine whether to proceed or break down, here is a simple example:
Frontier: ansible are all good, so let's talk about lookup plugins this plugin. Lookup_plugins is mainly used to implement extensions of various strings and variables within the extended playbook. For me personally, the use is not too big, but looked at the official Lookup_plugins extension list, there are some ideas. When you first use lookup, you encounter a problem where the data in {lookup}} is
0. IntroductionPlaybooks is the language of Ansible management configuration, deployment applications, and orchestration, and you can use playbooks to describe the policies you want to perform on the remote host or the set of steps that you perform.Similar to a set of task sets, defining information such as projects, organizational structures, profiles, and so on, the task is to organize the things you want to do in one step and the whole playbookOffi
:ok=2changed=1unreachable=0failed=0real0m35.901suser0m0.952ssys0m0.216s
4. Check for vulnerabilities
[emailprotected]:/etc/ansible16:36:01#ssh172.17.0.9[emailprotected]‘spassword:Lastlogin:ThuSep2516:35:572014from172.17.42.1[emailprotected]:~16:36:11#envx=‘(){:;};echovulnerable‘bash-c"echothisisatest"bash:warning:x:ignoringfunctiondefinitionattemptbash:errorimportingfunctiondefinitionfor`x‘thisisatest[emailprotected]:~
We can see that the vulnerability has been fixed.
Completed is
650) This. wid
Automated operations Tools: ansible
Application scenario for multi-process call Ansible API: Application System Check
An application system may have a cluster of 20-50 servers, and a preliminary system-level check can be checked with a unified playbook, such as (Df-h command). But deep into the application layer, there are some personalized applica
;#Ansible: TimeSync* * * * */5 */usr/sbin/ntpdate 172.16.0.1 >/dev/nullDelete Crontab[Email protected] ~]# ansible cce-m cron-a ' name= "TimeSync" state= "absent" '6. Use the Fetch module to pull the directory on the remote host to the local[Email protected] ~]# ansible cce-m fetch-a ' Src=/root/cce dest=/root/cce '7. Use the file module to manage files on the re
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.